﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Wpf_Examples.Views
{
    /// <summary>
    /// PopPanelWindow.xaml 的交互逻辑
    /// </summary>
    public partial class PopPanelWindow : Window
    {
        public PopPanelWindow()
        {
            InitializeComponent();
            // 注册窗口的鼠标点击事件
            this.MouseLeftButtonDown += PopPanelWindow_MouseLeftButtonDown;
        }


        private void TopButton_Click(object sender, RoutedEventArgs e)
        {
            // 触发顶部侧边栏的进入动画
            topBorder.Visibility = Visibility.Visible;
            Storyboard enterStoryboard = new Storyboard();
            DoubleAnimation enterAnimation = new DoubleAnimation
            {
                From = -100,
                To = 0,
                Duration = TimeSpan.FromSeconds(1.5),
                EasingFunction = new BackEase { Amplitude = 1, EasingMode = EasingMode.EaseOut }
            };
            Storyboard.SetTarget(enterAnimation, topTransform);
            Storyboard.SetTargetProperty(enterAnimation, new PropertyPath("Y"));
            enterStoryboard.Children.Add(enterAnimation);
            enterStoryboard.Begin();
        }

        private void BottomButton_Click(object sender, RoutedEventArgs e)
        {
            // 触发底部侧边栏的进入动画
            bottomBorder.Visibility = Visibility.Visible;
            Storyboard enterStoryboard = new Storyboard();
            DoubleAnimation enterAnimation = new DoubleAnimation
            {
                From = 0,
                To = 100,
                Duration = TimeSpan.FromSeconds(1.5),
                EasingFunction = new BackEase { Amplitude = 1, EasingMode = EasingMode.EaseOut }
            };
            Storyboard.SetTarget(enterAnimation, bottomTransform);
            Storyboard.SetTargetProperty(enterAnimation, new PropertyPath("Y"));
            enterStoryboard.Children.Add(enterAnimation);
            enterStoryboard.Begin();
        }


        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // 触发进入动画
            leftPanel.Visibility = Visibility.Visible;
            Storyboard enterStoryboard = new Storyboard();
            DoubleAnimation enterAnimation = new DoubleAnimation
            {
                From = 0,
                To = 200,
                Duration = TimeSpan.FromSeconds(1),
                EasingFunction = new BackEase { Amplitude = 0.5, EasingMode = EasingMode.EaseOut }
            };
            Storyboard.SetTarget(enterAnimation, toRight);
            Storyboard.SetTargetProperty(enterAnimation, new PropertyPath("X"));
            enterStoryboard.Children.Add(enterAnimation);
            enterStoryboard.Begin();
        }

        private void PopPanelWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // 检查点击的位置是否在左侧边栏之外
            if (!leftPanel.IsMouseOver && leftPanel.Visibility == Visibility.Visible)
            {
                // 触发退出动画
                Storyboard exitStoryboard = new Storyboard();
                DoubleAnimation exitAnimation = new DoubleAnimation
                {
                    From = 200,
                    To = 0,
                    Duration = TimeSpan.FromSeconds(0.6)
                };
                Storyboard.SetTarget(exitAnimation, toRight);
                Storyboard.SetTargetProperty(exitAnimation, new PropertyPath("X"));
                exitStoryboard.Children.Add(exitAnimation);
                exitStoryboard.Completed += (s, ev) => leftPanel.Visibility = Visibility.Collapsed;
                exitStoryboard.Begin();
            }


            // 检查点击的位置是否在顶侧边栏之外
            if (!topBorder.IsMouseOver && topBorder.Visibility == Visibility.Visible)
            {
                // 触发顶部侧边栏的退出动画
                Storyboard exitStoryboard = new Storyboard();
                DoubleAnimation exitAnimation = new DoubleAnimation
                {
                    From = 100,
                    To = 0,
                    Duration = TimeSpan.FromSeconds(1)
                };
                Storyboard.SetTarget(exitAnimation, topTransform);
                Storyboard.SetTargetProperty(exitAnimation, new PropertyPath("Y"));
                exitStoryboard.Children.Add(exitAnimation);
                exitStoryboard.Completed += (s, ev) => topBorder.Visibility = Visibility.Collapsed;
                exitStoryboard.Begin();
            }

            if (!bottomBorder.IsMouseOver && bottomBorder.Visibility == Visibility.Visible)
            {
                // 触发底部侧边栏的退出动画
                Storyboard exitStoryboard = new Storyboard();
                DoubleAnimation exitAnimation = new DoubleAnimation
                {
                    From = 100,
                    To = 0,
                    Duration = TimeSpan.FromSeconds(1)
                };
                Storyboard.SetTarget(exitAnimation, bottomTransform);
                Storyboard.SetTargetProperty(exitAnimation, new PropertyPath("Y"));
                exitStoryboard.Children.Add(exitAnimation);
                exitStoryboard.Completed += (s, ev) => bottomBorder.Visibility = Visibility.Collapsed;
                exitStoryboard.Begin();
            }


        }
    }
}
